package org.labuladong.动态规划算法.二维DP;

/**
 * @Auther: qingle
 * @Date: 2024/10/26-21:34
 * @Description:
 * @version: 1.0
 */
public class LC_122买卖股票的最佳时机IIDP {

	//用一次遍历的方法来找到最大利润，而不需要使用动态规划
	public static int maxProfit(int[] prices) {

		int minPrice = Integer.MAX_VALUE;
		int maxProfit = 0;
		int[] dp = new int[prices.length];
		dp[0] = prices[1];
//		dp[1] = prices[0];

		for (int i = 1; i < prices.length; i++) {
			if(prices[i] < minPrice){
				dp[i] = Math.max(dp[i],dp[i - 1] + 1);
			}
		}

		return dp[prices.length - 1];
	}

	public static void main(String[] args) {
		int[] prices = {7,1,5,3,6,4};
		System.out.println(maxProfit(prices));
	}
}
